<template>
  <div class="app-container">
    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="450px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="98px"
      >
        <el-col :span="24">
          <el-form-item label="调整日期" prop="yzmTzrq">
            <el-date-picker
              clearable
              size="small"
              v-model="queryParams.yzmTzrq"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择调整日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="调整班次" prop="yzmBbdm">
            <el-select
              v-model="queryParams.yzmBbdm"
              filterable
              placeholder="请选择班次"
              clearable
            >
              <el-option
                v-for="item in BbdmOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="运转记录编号" prop="yzmDjbh">
            <el-input
              v-model="queryParams.yzmDjbh"
              placeholder="请输入运转记录编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          @click="handleSearch"
          size="small"
          v-hasPermi="['production:workReport:query']"
        >
          查询
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          @click="handleDc('#exportWorkMx', '生产领料明细')"
          v-hasPermi="['production:workReport:export']"
          size="small"
        >
          明细数据
        </el-button>
      </el-col>
    </el-row>
    <el-tabs v-model="activeTab">
      <el-tab-pane label="明细数据" name="first">
        <el-table
          border
          stripe
          id="exportWorkMx"
          :height="tableH"
          @scrollBottom="load"
          :data="ReportList"
          :header-cell-style="{ 'text-align': 'center' }"
        >
          <el-table-column
            label="#"
            type="index"
            width="55"
            align="center"
            fixed="left"
          />
          <el-table-column
            label="调整日期"
            align="center"
            width="150"
            prop="yzm_tzrq"
          />
          <el-table-column
            label="运转记录编号"
            align="center"
            width="150"
            prop="yzd_djbh"
          />
          <el-table-column
            label="机台编号"
            align="center"
            width="150"
            prop="yzd_jtbh"
          />
          <el-table-column
            label="班次"
            :show-overflow-tooltip="true"
            width="60"
            align="center"
            prop="yzm_bbdm"
          >
            <template #default="scope">
              <dict-tag :options="BbdmOptions" :value="scope.row.yzm_bbdm" />
            </template>
          </el-table-column>
          <el-table-column label="客户编号" prop="itm_custwldm" width="130" />
          <el-table-column label="物料代码" prop="moe_wldm" width="130" />
          <el-table-column label="物料品名" prop="itm_pmgg" width="150" />
          <el-table-column
            label="机台计数"
            align="center"
            prop="yzd_jtsl"
            width="100"
          />
          <el-table-column
            label="调整数量"
            align="center"
            prop="yzd_sjsl"
            width="100"
          />
          <el-table-column
            label="良品调整差异"
            align="center"
            prop="yzd_tzsl"
            width="130"
          />
          <el-table-column
            label="备注"
            align="center"
            prop="yzm_desc"
            width="200"
          />
          <el-table-column
            label="操作人员1"
            align="center"
            prop="yzd_op1"
            width="130"
          />
          <el-table-column
            label="操作人员2"
            align="center"
            prop="yzd_op2"
            width="130"
          />
          <el-table-column
            label="操作人员3"
            align="center"
            prop="yzd_op3"
            width="130"
          />
          <el-table-column
            label="操作人员4"
            align="center"
            prop="yzd_op4"
            width="130"
          />
          <el-table-column
            label="操作人员5"
            align="center"
            prop="yzd_op5"
            width="130"
          />
          <el-table-column
            label="操作人员6"
            align="center"
            prop="yzd_op6"
            width="130"
          />
          <el-table-column
            label="操作人员7"
            align="center"
            prop="yzd_op7"
            width="130"
          />
          <el-table-column
            label="操作人员8"
            align="center"
            prop="yzd_op8"
            width="130"
          />
          <el-table-column
            label="建立人员"
            align="center"
            prop="yzm_jlry"
            width="100"
          />
          <el-table-column
            label="建立日期"
            align="center"
            prop="yzm_jlrq"
            width="150"
          />
        </el-table>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { WorkRecordReport } from "@/api/production/workRecord";
import { exportTable } from "@/utils/ruoyi";

export default {
  name: "workReport",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 非单个禁用
      tableH: document.body.clientHeight - 300,
      single: true,
      activeTab: "first",
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      BbdmOptions: [],
      // 总条数
      total: 0,
      total2: 0,
      // 运转记录表格数据
      ReportList: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        yzmDjbh: null,
        yzmTzrq: new Date(),
        yzmBbdm: null,
        yzmZtbz: 2,
        pageNum: 1,
        pageSize: 30,
      },

      // 表单参数
      form: {},
    };
  },
  created() {
    //班次代码
    this.getDicts("class_code").then((response) => {
      this.BbdmOptions = response.data;
    });
    this.getList();
  },
  methods: {
    /** 查询来料进货入库开单列表 */
    getList() {
      this.loading = true;
      if (this.queryParams.yzmTzrq != null && this.queryParams.yzmTzrq != "") {
        this.queryParams.yzmTzrq = this.moment(this.queryParams.yzmTzrq).format(
          "YYYY-MM-DD"
        );
      }
      this.queryParams.pageNum = 1;
      WorkRecordReport(this.queryParams).then((response) => {
        this.ReportList = [];
        this.ReportList = this.ReportList.concat(response.rows);
        this.total = response.total;
        this.loading = false;
      });
    },
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageSize = 30;
        this.queryParams.pageNum++;
        WorkRecordReport(this.queryParams).then((response) => {
          this.ReportList = this.ReportList.concat(response.rows);
          this.total = response.total;
          this.loading = false;
        });
      }
      return 0;
    },
    handleDc(a, b) {
      exportTable(a, b);
    },
    handleSearch() {
      this.openSearch = true;
      this.title = "运转记录统计分析";
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false;
      this.reset();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.ReportList = [];
      this.getList();
      this.openSearch = false;
    },
    //导出Excel
    handleExcel(index) {},
  },
};
</script>

<style scoped></style>
